import axios from 'axios';
import nProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { Message } from 'element-ui';
import route from "@/route";

const requests =axios.create({
    baseURL:"serviceCustomer/api",
    timeout:5000
})
//请求拦截器
requests.interceptors.request.use((config)=>{
    nProgress.start();
    return config;
})
//响应拦截器
requests.interceptors.response.use(
    (res)=>{
        nProgress.done();
        return res.data
    },
    (error)=>{
        Message({
            message:'服务器崩溃啦!!!请稍后重新登录系统',
            type:'error'
        })
        route.replace({
            name:'Login'
        })
        return Promise.reject(new Error('REQUEST FAIL!'))
    }
)

export default requests;

